home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / WTEK0593.ZIP;1 / SWITCH.ZIP / SCRLWIN.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-08  |  5.3 KB  |  119 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  SCRLWIN.H                                                             */
  4. /*                                                                        */
  5. /*  Header file for Scrollers and ScrollableText                          */
  6. /*                                                                        */
  7. /*------------------------------------------------------------------------*/
  8.  
  9. #if !defined( SCRLWIN_H )
  10. #define SCRLWIN_H
  11.  
  12. #include "textwin.h"
  13.  
  14. /*------------------------------------------------------------------------*/
  15. /*                                                                        */
  16. /*  class Scroller                                                        */
  17. /*                                                                        */
  18. /*  Base class for HScroller and VScroller. Provides basic                */
  19. /*  implementation of scrolling.                                          */
  20. /*                                                                        */
  21. /*------------------------------------------------------------------------*/
  22.  
  23. class Scroller : public virtual WinData
  24. {
  25. protected:
  26.     enum Type { Horz = SB_HORZ, Vert = SB_VERT };
  27.     Scroller( Type which ) : Which( which ), Pos(0) {}
  28.     long OnScroll( unsigned );
  29.     virtual int GetPageSize() const = 0;
  30.     int GetPos() const { return Pos; }
  31.     void SetTextSize( int );
  32.     void SetWinSize( int );
  33. private:
  34.     int Pos;
  35.     int TextSize;
  36.     Type Which;
  37. };
  38.  
  39. /*------------------------------------------------------------------------*/
  40. /*                                                                        */
  41. /*  class VScroller                                                       */
  42. /*                                                                        */
  43. /*  Mixin class to handle vertical scrolling                              */
  44. /*                                                                        */
  45. /*------------------------------------------------------------------------*/
  46.  
  47. class VScroller : public Scroller, public virtual Dispatcher
  48. {
  49. public:
  50.     static void Register( UINT m, FuncType t, DispatchRecord<VScroller>::VoidFunc p )
  51.         { Map.add( DispatchRecord<VScroller>( m, t, p ) ); }
  52. protected:
  53.     VScroller() : Scroller( Vert )
  54.         { RegisterProc( WM_VSCROLL, &VScroller::OnScroll ); }
  55.     long OnScroll( unsigned where ) { return Scroller::OnScroll( where ); }
  56.     int GetPageSize() const { return GetWinHeight()/GetCharHeight(); }
  57.     virtual int Dispatch( UINT, UINT, LONG, LONG& );
  58. private:
  59.     static BI_SVectorImp<DispatchRecord<VScroller> > Map;
  60. };
  61.  
  62.  
  63. /*------------------------------------------------------------------------*/
  64. /*                                                                        */
  65. /*  class HScroller                                                       */
  66. /*                                                                        */
  67. /*  Mixin class to handle horizontal scrolling                            */
  68. /*                                                                        */
  69. /*------------------------------------------------------------------------*/
  70.  
  71. class HScroller : public Scroller, public virtual Dispatcher
  72. {
  73. public:
  74.     static void Register( UINT m, FuncType t, DispatchRecord<HScroller>::VoidFunc p )
  75.         { Map.add( DispatchRecord<HScroller>( m, t, p ) ); }
  76. protected:
  77.     HScroller() : Scroller( Horz )
  78.         { RegisterProc( WM_HSCROLL, &HScroller::OnScroll ); }
  79.     long OnScroll( unsigned where ) { return Scroller::OnScroll( where ); }
  80.     int GetPageSize() const { return GetWinWidth()/GetCharWidth(); }
  81.     virtual int Dispatch( UINT, UINT, LONG, LONG& );
  82. private:
  83.     static BI_SVectorImp<DispatchRecord<HScroller> > Map;
  84. };
  85.  
  86. /*------------------------------------------------------------------------*/
  87. /*                                                                        */
  88. /*  class ScrollableText                                                  */
  89. /*                                                                        */
  90. /*  Mixes TextWindow, VScroller, and HScroller to provide                 */
  91. /*  a scrollable text window.                                             */
  92. /*                                                                        */
  93. /*------------------------------------------------------------------------*/
  94.  
  95. class ScrollableText : public TextWindow,
  96.                        private VScroller,
  97.                        private HScroller
  98. {
  99. public:
  100.     ScrollableText()
  101.         {
  102.         VScroller::SetTextSize( Lines() );
  103.         HScroller::SetTextSize( Width() );
  104.         }
  105.     void Create( HWND handle, int show, DWORD flags = 0 )
  106.         { TextWindow::Create( handle, show, flags | WS_VSCROLL | WS_HSCROLL ); }
  107. protected:
  108.     int GetXPos() const { return HScroller::GetPos(); }
  109.     int GetYPos() const { return VScroller::GetPos(); }
  110.     void Resized()
  111.         {
  112.         VScroller::SetWinSize( GetWinHeight()/GetCharHeight()-1 );
  113.         HScroller::SetWinSize( GetWinWidth()/GetCharWidth()-1 );
  114.         }
  115.     virtual int Dispatch( UINT, UINT, LONG, LONG& );
  116. };
  117.  
  118. #endif  // SCRLWIN_H
  119.